﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QLDAOL.Models;
using QLDAOL.Util;
using QLDAOL.ModelView;
using System.Web.Mvc.Ajax;
using System.Web.Routing;
namespace QLDAOL.Controllers
{
    public static class HtmlHelperExtensions
    {
        public static MvcHtmlString RawActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, string controllerName, object routeValues, AjaxOptions ajaxOptions, object htmlAttributes)
        {
            //var repID = Guid.NewGuid().ToString();
            //var lnk = ajaxHelper.ActionLink(repID, actionName, controllerName, routeValues, ajaxOptions, htmlAttributes);
            //return MvcHtmlString.Create(lnk.ToString().Replace(repID, linkText));

            var urlHelper = new UrlHelper(ajaxHelper.ViewContext.RequestContext);
            var anchor = new TagBuilder("a");
            anchor.InnerHtml = linkText;
            anchor.Attributes["href"] = urlHelper.Action(actionName, controllerName, routeValues);
            anchor.MergeAttributes(new RouteValueDictionary(htmlAttributes));
            return MvcHtmlString.Create(anchor.ToString());
        }
    }  
    public class InfomationController : BaseController
    {
        //
        // GET: /Index/
        public IEQLDAOLRepository repository = new IEQLDAOLRepository();
        public ActionResult InfoDetail(int info=0)
        {
            int id = int.Parse(Session["pjID"].ToString());
            int userID = 1; //Danh
            bool checkaccess = false;
            if (id > 0)
                checkaccess = repository.checkPJAccess(id, userID);
            if (checkaccess)
            {
                
                var inf= repository.getInfoByID(info);
                ViewData["info"] = inf;
                return View();
            }
            return RedirectToAction("AccessDenied");
        }
        public ActionResult ListInfo(int type=1)
        {
            int userID = 1; //Danh
            int id = int.Parse(Session["pjID"].ToString());
            bool checkaccess = false;
            if (id > 0)
                checkaccess = repository.checkPJAccess(id, userID);
            if (checkaccess)
            {
                var lstInfo = repository.getlstNewsQA(type, id);
                ViewData["lstInfo"] = lstInfo;
                return View();
            }
            return RedirectToAction("AccessDenied");
            
        }
    }
}
